home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 13 - PowerPC / Optimize 2 / Blitter.c next >
Text File  |  1995-03-06  |  2KB  |  90 lines

  1. /*********************/
  2. /*     BLITTER.C     */
  3. /*********************/
  4. //
  5. // This file contains the "poor man's profiler" and
  6. // the screen blitter routine.
  7. //
  8.  
  9. /****************************/
  10. /*    EXTERNALS             */
  11. /****************************/
  12.  
  13. extern    Ptr            gScreenAddr,gDrawBufferPtr;
  14. extern    long        gScreenRowBytes;
  15.  
  16.  
  17. /****************************/
  18. /*    PROTOTYPES            */
  19. /****************************/
  20.  
  21. void ProfileIt(void);
  22. static void BlitBufferToScreen(void);
  23.  
  24.  
  25. /****************************/
  26. /*    CONSTANTS             */
  27. /****************************/
  28.  
  29.  
  30. /****************************/
  31. /*    VARIABLES             */
  32. /****************************/
  33.  
  34.  
  35.  
  36. /********************* PROFILE IT *********************/
  37. //
  38. // Calls the blitter routine 1000 times and does a
  39. // beep at the beginning and end so you can time in
  40. // on a stopwatch.
  41. //
  42.  
  43. void ProfileIt(void)
  44. {
  45. long    i;
  46.  
  47.     SysBeep(0);                                    // MAKE 1ST BEEP SOUND
  48.     
  49.     for (i=0; i < 1000L; i++)                    // blit the buffer 1000 times
  50.         BlitBufferToScreen();
  51.         
  52.     SysBeep(0);                                    // MAKE 2ND BEEP SOUND    
  53. }
  54.  
  55.  
  56. /*************** BLIT BUFFER TO SCREEN ****************/
  57. //
  58. // This is a partially optimized blitter routine which
  59. // will blit the 640x480 buffer to the screen.
  60. //
  61. // This has been optimized by using doubles to copy 8 bytes
  62. // of data at a time.
  63. //
  64. // On a PowerMac 6100/60 it takes approximately 15 seconds
  65. // to execute this 1000 times.
  66. //
  67.  
  68. static void BlitBufferToScreen(void)
  69. {
  70. long    x,y;
  71. double    *destPtr,*srcPtr;
  72. Ptr        destStartPtr;
  73.  
  74.     srcPtr = (double *)gDrawBufferPtr;            // get ptr to start of buffer
  75.     destStartPtr = gScreenAddr;                    // get ptr to start of scan line
  76.  
  77.     for(y=0; y < 480; y++)
  78.     {
  79.         destPtr = (double *)destStartPtr;        // set destPtr to start of line
  80.         
  81.         for (x=0; x < (640/8); x++)                // copy a line with 8-byte doubles
  82.             *destPtr++ = *srcPtr++;
  83.  
  84.         destStartPtr += gScreenRowBytes;        // skip to next scan line
  85.     }
  86. }
  87.  
  88.  
  89.  
  90.